package com.yanqingying;
import io.jsonwebtoken.*;

import java.util.Date;
import java.util.Map;

public class JwtsTest {
    public static String sigKey ="YanQingYing";
    public static Long time = 200000000000000000L;
    public static String JwtBuild(Map<String ,Object> claim){
        String a = Jwts.builder()
                .addClaims(claim)
                .signWith(SignatureAlgorithm.HS256, sigKey)
                .setExpiration(new Date(System.currentTimeMillis() + time))
                .compact();
        return a;
    }
    public static Claims JwtParser(String claims){
        try {
            Claims b = Jwts.parser()
                    .setSigningKey(sigKey)
                    .parseClaimsJws(claims)
                    .getBody();
            return b;
        } catch (ExpiredJwtException e) {
            throw new RuntimeException("Token解析失败",e);
        }
    }
}
